package com.zhang;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestRegex {

    public static void main(String[] args) {
//        System.out.println(isLockNessMonster("tree fiddy123"));

        String serviceAddress = "http://login/${0}/${1}/${3}";
        String methodPath = "/internal/(aaa)/(.*)/daf/(.*)/(.*)/aada";
        String pStr1 = "\\(.+?\\)";
        Pattern pattern21 = Pattern.compile(pStr1);
        Matcher matcher21 = pattern21.matcher(methodPath);
        int cc=0;
        while (matcher21.find()){
//            System.out.println(matcher21.groupCount());
//            System.out.println(matcher21.group(0));
//            System.out.println(matcher21.group(1));
            cc++;
        }

        System.out.println("pStr1 count:"+cc);


        Pattern p1 = Pattern.compile(methodPath);
        Matcher matcher1 = p1.matcher("");
        int i2 = matcher1.groupCount();
        System.out.println("methodPath groupCount:" + i2);

        String s1 = "\\$\\{\\d+\\}";
        p1 = Pattern.compile(s1);
        matcher1 = p1.matcher(serviceAddress);
        int aaa = 0;
        while (matcher1.find()) {
            aaa++;
        }

        System.out.println("serviceAddress num:" + cc);

        // 按指定模式在字符串查找
        String line = "dddd2cc";
        String pattern = "(\\D*)(\\d+)(.*)(cc)(ab)a";

        // 创建 Pattern 对象
        Pattern r = Pattern.compile(pattern);

        // 现在创建 matcher 对象
        Matcher m = r.matcher("");
        int i1 = m.groupCount();
        System.out.println("groutCount:" + i1);
        if (m.find()) {
            System.out.println("Found value: " + m.group(0));
            System.out.println("Found value: " + m.group(1));
            System.out.println("Found value: " + m.group(2));
            System.out.println("Found value: " + m.group(3));
        } else {
            System.out.println("NO MATCH");
        }


        String regex = "(\\$\\{\\d+\\})";
        String str = "d${1}ff/$d{a}ff/${2}/${3}";
        Pattern compile = Pattern.compile(regex);
        Matcher matcher = compile.matcher(str);

        int i = matcher.groupCount();
        System.out.println("count:" + i);


        System.out.println(str.matches(regex));
        System.out.println("${033}:" + Pattern.matches(regex, str));

        //校验qq号码
        //1: 要求必须是5-15位数字
        //2: 0不能开头
        regex = "[0-5][5-9]{4,14}";
        //描述qq号
        String qq = "56898989";
        //判断
        boolean flag = qq.matches(regex);
        System.out.println(flag);

        //替换
        String stt = "as5fdsfdsfds5f48fdsf564fds";
//        String re="[0-9]";//替换:as*fdsfdsfds*f**fdsf***fds
        String re = "[0-9]+";//替换: as*fdsfdsfds*f*fdsf*fds
        String s = stt.replaceAll(re, "*");
        System.out.println("替换:" + s);


    }

    public static boolean isLockNessMonster(String s) {
        return Pattern.matches(".*(tree fiddy|3\\.50|three fifty).*", s);
    }


}
